package com.heatup.apt.management.controller;

import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
import com.heatup.apt.model.management.SysUser;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * Base控制器
 * <P>File name : BaseController.java </P>
 * <P>Author : fangxiaowen </P> 
 * <P>Date : 2016年8月24日 </P>
 */
@SuppressWarnings("unchecked")
public class BaseController {
	
	@Autowired
	private HttpSession session;
	
	public static final String SESSION_KEY_USERINFO = "sys_user";
	public static final String SESSION_KEY_MOBILE = "MOBILE";
	public static final String SESSION_KEY_CHECK_CODE = "CHECK_CODE";
	public static final String SESSION_KEY_CHECK_CODE_LAST_SEND = "CHECK_CODE_LAST_SEND";
	protected void setSession(String key, Object value){
		session.setAttribute(key, value);
	}
	
	protected Object getSession(String key){
		return session.getAttribute(key);
	}	
	
	
	/**
	 * 获取用户信息
	 * BaseController.getUserInfo()<BR>
	 * <P>Author :  fangxiaowen </P>  
	 * <P>Date : 2016年9月23日 </P>
	 * @return
	 */
	public SysUser getUserInfo(){
		Object obj = session.getAttribute(SESSION_KEY_USERINFO);
		if(obj != null){
			return (SysUser)obj;
		}else{
			return null;
		}		
	}
	
    /**
     * 分发数据到页面接收 BaseController.responseSendMsg()<BR>
     * BaseController.responseSendMsg()<BR>
     * <P>Author :  fangxiaowen </P>  
     * <P>Date : 2016年9月19日 </P>
     * @param response
     * @param strMsg
     */
	protected void responseSendMsg(HttpServletResponse response, String strMsg) {
		try {
			response.setContentType("application/json;charset=utf-8");
			response.setCharacterEncoding("utf-8");
			response.getWriter().write(strMsg);
			response.getWriter().flush();
			response.getWriter().close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
